﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using StockTrader.DAL.HoseAdapter.FileParser;
using StockTrader.DAL.HoseAdapter.FileParser.Structure;
using System.Collections;
using StockTrader.DAL.HoseAdapter.Lib.Threading;
using StockTrader.DAL.HoseAdapter.FileViewer.DataAccess;

namespace StockTrader.DAL.HoseAdapter.FileViewer
{
    public partial class Form1 : Form
    {
        private void LoadCombo()
        {
            string strXML = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "") + "Config\\FileDir.xml";
            DataSet ds = new DataSet();
            ds.ReadXml(strXML);
            if (ds.Tables.Count > 0)
            {
                cboFileList.Items.Clear();
                cboFileList.DisplayMember = "KeyName";
                cboFileList.ValueMember = "KeyCode";
                cboFileList.DataSource = ds.Tables["FileConfig"];
                cboFileList.SelectedIndex = 0;
            }
        }
        private DataAccessClient _DALclient;
        private void LoadGrid()
        {
            switch (cboFileList.SelectedValue.ToString())
            {
                case CTCI_SUBDIR.OrderCancellation:
                    {
                        //gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(OrderCancellation));
                        _DALclient = new DataAccessClient(this.gvFileMonitor, dtHistory.Value, typeof(OrderCancellation));
                        _DALclient.Execute();
                        break;
                    }
                case CTCI_SUBDIR.OrderChange:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(OrderChange));
                        break;
                    }
                case CTCI_SUBDIR.Advertisement:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(Advertisment));
                        break;
                    }
                case CTCI_SUBDIR.OFPThroughDeal:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(OFPTDeal));
                        break;
                    }
                case CTCI_SUBDIR.TFPThroughDeal:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(TFPTDeal));
                        break;
                    }
                case CTCI_SUBDIR.NewConditionedOrder:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(NewConditionedOrder));
                        break;
                    }
                case CTCI_SUBDIR.OrderConfirmation:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(OrderConfirmation));
                        break;
                    }
                case CTCI_SUBDIR.ConfirmOfOrderCancel:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(ConfirmOrderCancel));
                        break;
                    }
                case CTCI_SUBDIR.ConfirmOfOrderChange:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(ConfirmOrderChange));
                        break;
                    }
                case CTCI_SUBDIR.DealConfirmation:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(DealConfirmation));
                        break;
                    }
                case CTCI_SUBDIR.PutThroughAcknowledgment:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(PutThroughACK));
                        break;
                    }
                case CTCI_SUBDIR.Reject:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(Reject));
                        break;
                    }
                case CTCI_SUBDIR.CrossingDealConfirm:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(CrossingDealConfirm));
                        break;
                    }
                case CTCI_SUBDIR.PutThroughDealConfirmation:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(PutThroughDealConfirmation));
                        break;
                    }
                case CTCI_SUBDIR.PutThroughDealReply:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(PutThroughDealReply));
                        break;
                    }
                case CTCI_SUBDIR.DealCancelRequest:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(DealCancelRequest));
                        break;
                    }
                case CTCI_SUBDIR.DealCancelReply:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(DealCancelReply));
                        break;
                    }
                case PRS_FILE.SECURITY:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(Securities));
                        break;
                    }
                case PRS_FILE.DELIST:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(DeList));
                        break;
                    }
                case PRS_FILE.FROOM:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(Froom));
                        break;
                    }
                case PRS_FILE.LE:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(Le));
                        break;
                    }
                case PRS_FILE.MARKET_STAT:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(MarketStat));
                        break;
                    }
                case PRS_FILE.NEWLIST:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(NewList));
                        break;
                    }
                case PRS_FILE.PUT_AD:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(PutAd));
                        break;
                    }
                case PRS_FILE.PUT_DC:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(PutDc));
                        break;
                    }
                case PRS_FILE.PUT_EXEC:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(PutExec));
                        break;
                    }
                case PRS_FILE.TOTAL_MARKET:
                    {
                        gvFileMonitor.DataSource = FileEngineer.RetrieveFileInfo(dtHistory.Value, typeof(TotalMkt));
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LoadCombo();
            LoadGrid();
        }

        private void cboFileList_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadGrid();
        }
    }
}
